home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / IIGS / TN.IIGS.096 < prev    next >
Encoding:
Text File  |  1991-01-11  |  7.8 KB  |  232 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. Apple IIgs
  7. #96:  Standard File Customization
  8.  
  9. Written by:    Dan Strnad                                       November 1990
  10.  
  11. This Technical Note discusses particulars of using custom dialog boxes for the
  12. Open and Save File dialog boxes and custom drawing routines to display the files
  13. and folders listed.
  14. _____________________________________________________________________________
  15.  
  16.  
  17. About the Templates
  18.  
  19. Volume 3 of the Apple IIgs Toolbox Reference states the following about the Open
  20. File dialog box template for Standard File:
  21.  
  22. "The scroll bar item (item5) is not used for single-file calls.  For multifile
  23. calls, this item contains the Accept Button Definition."
  24.  
  25. What is not stated explicitly is that, although the scroll bar item is not used
  26. for single-file calls, a place holder for it must be included in the dialog box
  27. template.  Another particular not explicitly stated is that the strings used by
  28. the item templates must be Pascal strings; no listType field is provided in the
  29. extended list control record as was present in the List Manager's original list
  30. record structure.
  31.  
  32.  
  33. Custom Item Draw Procedures
  34.  
  35. Custom item draw procedures have the rectangle in which the item is to be drawn,
  36. the List Manager's memrec structure corresponding to that item, and a handle to
  37. the extended list control record available on the stack.  By including a custom
  38. item draw procedure, programs are able to get a handle to the extended list
  39. control record.  The custom item draw procedure could also make the handle
  40. available to other routines, such as the dialogHook routine.  With the handle,
  41. programs can now perform specialized operations during a standard file call,
  42. such as checking which item is selected before allowing the user to cancel.  The
  43. code fragment below (from DTS Apple II Sample Code #18, AccessPriv) illustrates
  44. the use of SFPGetFile2 with a custom item draw routine.
  45.  
  46. static char SaveStr[] = "\pSave";
  47. static char OpenStr[] = "\pOpen";
  48. static char CloseStr[] = "\pClose";
  49. static char DriveStr[] = "\pDrive";
  50. static char CancelStr[] = "\pCancel";
  51. static char FolderStr[] = "\pNew Folder";
  52. static char AcceptStr[] = "\pAccept";
  53.  
  54.  
  55. ItemTemplate OpenBut640 =   {1,
  56.                             61,265,73,375,
  57.                             buttonItem,
  58.                             OpenStr,
  59.                             0,
  60.                             0,
  61.                             0L};
  62.  
  63. ItemTemplate CloseBut640 =  {2,
  64.                             79,265,91,375,
  65.                             buttonItem,
  66.                             CloseStr,
  67.                             0,
  68.                             0,
  69.                             0L};
  70.  
  71. ItemTemplate NextBut640 =   {3,
  72.                             25,265,37,375,
  73.                             buttonItem,
  74.                             DriveStr,
  75.                             0,
  76.                             0,
  77.                             0L};
  78.  
  79. ItemTemplate CancelBut640 = {4,
  80.                             97,265,109,375,
  81.                             buttonItem,
  82.                             CancelStr,
  83.                             0,
  84.                             0,
  85.                             0L};
  86.  
  87. ItemTemplate Scroll640 =    {5,
  88.                             43,265,55,375,
  89.                             buttonItem,
  90.                             AcceptStr,
  91.                             0,
  92.                             0,
  93.                             0L};
  94.  
  95. ItemTemplate Path640 =      {6,
  96.                             12,15,24,395,
  97.                             userItem,
  98.                             0L,
  99.                             0,
  100.                             0,
  101.                             0L};
  102.  
  103. ItemTemplate Files640 =     {7,
  104.                             25,18,107,215,
  105.                             userItem + itemDisable,
  106.                             0L,
  107.                             0,
  108.                             0,
  109.                             0L};
  110.  
  111. ItemTemplate Prompt640 =    {8,
  112.                             3,15,12,395,
  113.                             statText + itemDisable,
  114.                             0L,
  115.                             0,
  116.                             0,
  117.                             0L};
  118.  
  119.  
  120. /*************************************************************************
  121. *
  122. * myDialogHook
  123. *
  124. ***************************************************************************/
  125.  
  126. pascal void myDialogHook(strip1,strip2)
  127. long strip1;
  128. long strip2;
  129. {
  130. }
  131.  
  132. /*************************************************************************
  133. *
  134. * CustomItemDraw
  135. *
  136. **************************************************************************/
  137.  
  138. pascal void CustomItemDraw(itemDrawPtr)
  139. Pointer itemDrawPtr;
  140. {
  141. static unsigned int flag, dbr;        /* result, data bank register value */
  142. byte          StringCount;
  143. char          *ItemPascalString;
  144. Word          ItemFileType;
  145. Long          ItemAuxType;
  146. Rect          *TheItemRectPtr;
  147. MemRec        *TheMemRecPtr;
  148. CtlRecHndl    TheSFListControlHndl;
  149. Point         MyOldPenPos,
  150.               MyNewPenPos;
  151.  
  152. static char FileString[] = "xxxx yyyyyyyy ";
  153.  
  154. /* save our data bank and set current to global page */
  155. dbr = SaveDB();
  156. /* Get the Rect from High on the Stack */
  157. TheItemRectPtr = (Rect *)(*((long *)(((long)&itemDrawPtr)+ 36L)));
  158.                                                  /* save old pen position */
  159. GetPen(&MyOldPenPos);                            /* Set our pen position */
  160. MyNewPenPos.h = TheItemRectPtr->h1 + 5;
  161. MyNewPenPos.v = TheItemRectPtr->v2 -2;
  162. MoveTo(MyNewPenPos);                             /* relocate the pen */
  163.  
  164. /* get our member record; this is just to reveal where it is on the stack */
  165. TheMemRecPtr = (MemRec *)(*((long *)(((long)&itemDrawPtr)+ 32L)));
  166.  
  167. /* get the list cntrol handle; ditto */
  168. TheSFListControlHndl = (CtlRecHndl)(*((long *)(((long)&itemDrawPtr)+ 28L)));
  169.  
  170. StringCount = (byte) *itemDrawPtr;               /* get the string length */
  171. ItemPascalString = itemDrawPtr;                  /* set our user string */
  172. ItemFileType =  *(Word *)(itemDrawPtr+StringCount+1L); /* get our FileType */
  173. ItemAuxType =  *(Long *)(itemDrawPtr+StringCount+3L);  /* get our AuxType */
  174.  
  175. /* format for display */
  176. sprintf(FileString, "%.4x-%.8lx ",ItemFileType,ItemAuxType);
  177. c2pstr(FileString);                /* turn it into a P string */
  178. DrawString(FileString);            /* Draw it */
  179. DrawString(ItemPascalString);      /* catenate File name to the other info */
  180. FrameRect(TheItemRectPtr);
  181. MoveTo(MyOldPenPos);               /* return the pen to starting position */
  182. RestoreDB(dbr);                    /* restore our data bank */
  183.  
  184. }
  185.  
  186. /*************************************************************************
  187. *
  188. * ChooseFolder
  189. *
  190. * presents user with dialog to select folder to show/set privileges of
  191. *
  192. **************************************************************************/
  193.  
  194. void    SomeProc()
  195. {
  196. DialogTemplate GetDialog640;
  197.  
  198. GetDialog640.dtBoundsRect.v1 = 0;
  199. GetDialog640.dtBoundsRect.h1 = 0;
  200. GetDialog640.dtBoundsRect.v2 = 114;
  201. GetDialog640.dtBoundsRect.h2 = 400;
  202. GetDialog640.dtVisible = -1;
  203. GetDialog640.dtRefCon = 0L;
  204. GetDialog640.dtItemList[0] = &OpenBut640;
  205. GetDialog640.dtItemList[1] = &CloseBut640;
  206. GetDialog640.dtItemList[2] = &NextBut640;
  207. GetDialog640.dtItemList[3] = &CancelBut640;
  208. GetDialog640.dtItemList[4] = &Scroll640;
  209. GetDialog640.dtItemList[5] = &Path640;
  210. GetDialog640.dtItemList[6] = &Files640;
  211. GetDialog640.dtItemList[7] = &Prompt640;
  212. GetDialog640.dtItemList[8] = 0L;
  213.  
  214. SFPGetFile2(    /* user selection of folder to get/set privs of */
  215.             120, 53,
  216.             CustomItemDraw,
  217.             refIsPointer,
  218.             prompt,
  219.             0L,
  220.             0L,
  221.             &GetDialog640,
  222.             myDialogHook,
  223.             &myReply
  224. );
  225.  
  226.  
  227. Further Reference
  228. _____________________________________________________________________________
  229.   o     Apple IIgs Toolbox Reference, Volumes 1 & 3
  230.   o     DTS Apple II Sample Code #18, AccessPriv
  231.  
  232.